package com.pda.xinma.presenter;

import com.pda.xinma.bean.HandingInDetailBean;
import com.pda.xinma.bean.LoginBean;
import com.pda.xinma.bean.request.HandingInRequest;
import com.pda.xinma.contract.HandingInContract;
import com.pda.xinma.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import io.reactivex.functions.Consumer;

public class HandingInPresenter extends BasePresenter<HandingInContract.View>  implements HandingInContract.Presenter {

    @Override
    public void queryEntryShelvesInfo(String entryNo, String rollerId) {
        NetUtils.geApi().queryEntryShelvesInfo(entryNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<HandingInDetailBean>>() {
                    @Override
                    public void accept(BaseAppEntity<HandingInDetailBean> handingInDetailBeanBaseAppEntity) throws Exception {
                        getView().setData(handingInDetailBeanBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void confirmIssued(HandingInRequest body) {
        NetUtils.geApi().confirmIssued(body)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<LoginBean>>() {
                    @Override
                    public void accept(BaseAppEntity<LoginBean> loginBeanBaseAppEntity) throws Exception {
                        getView().onSuccess();
                        getView().showMessage(loginBeanBaseAppEntity.getMessage());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void queryActualWeight(String rollerId) {
        NetUtils.geApi().queryActualWeight(rollerId)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<String>>() {
                    @Override
                    public void accept(BaseAppEntity<String> handingInDetailBeanBaseAppEntity) throws Exception {
                        getView().setWeight(handingInDetailBeanBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void queryEntryScanShelvesInfo(String thirdOrderNo,HandingInDetailBean data) {
        NetUtils.geApi().queryEntryScanShelvesInfo(thirdOrderNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<HandingInDetailBean>>() {
                    @Override
                    public void accept(BaseAppEntity<HandingInDetailBean> handingInDetailBeanBaseAppEntity) throws Exception {
                        data.setEntryNo(handingInDetailBeanBaseAppEntity.getData().getEntryNo());
                        data.setNumId(handingInDetailBeanBaseAppEntity.getData().getNumId());
                        data.setSku(handingInDetailBeanBaseAppEntity.getData().getSku());
                        getView().setScanData(data);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                        getView().finishActivity();
                    }
                });
    }
}
